var mousex;
var mousey;
var move = false;
var ldivx = window.innerWidth/2;
var ldivy = window.innerHeight/2-100;

window.onload = init;
var t;
var d;
var textbox;
function init() {
	t = document.getElementsByTagName('input');
	d = document.getElementById('dragme');
	d.onmousedown = mousedown;
	document.body.onmouseup = mouseup;
	document.body.onmousemove = mousemove;
	d.style.left = ldivx + 'px';
	d.style.top = ldivy + 'px';
	d.style.display = 'block';
	/*for(i=0; i<t.length; i++)
	{
		if(t.item(i).type == 'text' || 'password')
		{
			t.item(i).onmousedown = function() { 
				textbox = true;				
			}		
			t.item(i).onmouseup = function() { 
				textbox = false;				
			}
		}
	}*/
}

function mousedown(e) {			
	if(!textbox)
	{
		if (!e)
			var e = window.event;
		move = true;
		mousex = e.clientX;
		mousey = e.clientY; 
		document.body.style.cursor = "move";
	}
}

function mouseup(e) {
	if (!e)
		var e = window.event;                
	move = false;
	document.body.style.cursor = "default";
}

function mousemove(e) {
	if (move) {
		if (!e)
			var e = window.event;
		ldivx = parseInt(ldivx) + parseInt(e.clientX) - parseInt(mousex);
		ldivy = parseInt(ldivy) + parseInt(e.clientY) - parseInt(mousey);

		mousex = e.clientX;
		mousey = e.clientY;

		var d = document.getElementById('dragme');
		d.style.left = parseInt(ldivx) + 'px';
		d.style.top = parseInt(ldivy) + 'px';
	}
}
